package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import sun.applet.resources.MsgAppletViewer_ko;
import vo.Msg;

import dao.MsgDao;

public class ChangeMsgServlet extends HttpServlet {

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		this.doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		HttpSession hs=request.getSession();
		String username=hs.getAttribute("username").toString();
		
		int mid=Integer.parseInt(request.getParameter("mid"));
		String name=new String(request.getParameter("name").getBytes("ISO-8859-1"),"GBK");
		String photo=new String(request.getParameter("photo").getBytes("ISO-8859-1"),"GBK");
		String type=new String(request.getParameter("type").getBytes("ISO-8859-1"),"GBK");	
		String people=username;
	//	String money=new String(request.getParameter("money").getBytes("ISO-8859-1"),"GBK");
		String area=new String(request.getParameter("area").getBytes("ISO-8859-1"),"GBK");
		String tel=new String(request.getParameter("tel").getBytes("ISO-8859-1"),"GBK");
		String flag=new String(request.getParameter("flag").getBytes("ISO-8859-1"),"GBK");
		String detail=new String(request.getParameter("detail").getBytes("ISO-8859-1"),"GBK");
		String xiaoqu=new String(request.getParameter("xiaoqu").getBytes("ISO-8859-1"),"GBK");
		
		MsgDao dao=new MsgDao();
		dao.updateMsg(mid, name, photo, type, people, area, tel, detail, flag,xiaoqu);
		response.sendRedirect("ListMyMsgServlet");
	}

}
